package com.xiezhr.pbideaapitestdemo.config;

import com.xiezhr.pbideaapitestdemo.webservise.CodeServise;
import com.xiezhr.pbideaapitestdemo.webservise.impl.CodeServiseImpl;

import jakarta.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: pbideaApiTestDemo
 * @description:
 * @author: xie.zhr
 * @create: 2024-12-09 10:56
 **/
@Configuration
public class WebServiceConfig {
    @Bean(name = "cxfServlet")  // 注入servlet bean name不能dispatcherServlet ,否则会覆盖dispatcherServlet
    public ServletRegistrationBean<CXFServlet> cxfServlet() {
        return new ServletRegistrationBean<CXFServlet>(new CXFServlet(), "/webservice/*");
    }
    @Bean
    public CodeServise codeService() {
        return new CodeServiseImpl();
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
    @Bean
    public Endpoint endpoint() {
        // 参数二，是SEI实现类对象
        EndpointImpl endpoint = new EndpointImpl(this.springBus(), this.codeService());
        // 发布服务
        endpoint.publish("/userService");
        return endpoint;

    }
}
